<?php

namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller {
	// 展示首页
	public function index() {
		$data['arts'] = D('article')->field('aid,title,ymd')->where(array('is_del' => 0, 'cid' => 7))->order('ymd desc')->limit(4)->select();
		$data['list'][] = D('article')->where('cid=4')->field('aid,title,content,pic1,ymd')->order('ymd desc')->limit(1)->find();
		$data['list'][] = D('article')->where('cid=5')->field('aid,title,content,pic1,ymd')->order('ymd desc')->limit(1)->find();
		$data['list'][] = D('article')->where('cid=6')->field('aid,title,content,pic1,ymd')->order('ymd desc')->limit(1)->find();
		$this->assign('arts', $data['arts']);
		$this->assign('list', $data['list']);
		$this->display('./indexindex.html');
	}

	public function user() {
		$users = D('user')->where('is_del=0')->order('sort desc')->select();
		$this->ajaxReturn(ajax_data(1, '', $users));
	}

	/**
	 * 列表页
	 */
	public function xin() {
		$cid = I('cid/d');
		if ($cid) {
			$where['cid'] = $cid;
			$where['is_del'] = 0;
			// if ($cid < 4) {
			// 	$arts = D('article')->field('aid,title,content,pic1,ymd')->where($where)->limit(20)->select();
			// 	$arts['foud'] = D('foud')->field('money,school,earnings_number')->find(1);
			// 	if (is_array($arts)) {
			// 		$this->ajaxReturn(ajax_data(1, '', $arts));
			// 	}
			// }
			$artModel = D('article');
			$count = $artModel->where($where)->count();
			$Page = new \Think\Page($count, $cid<4?20:2);
			$arts = $artModel->field('aid,title,content,ymd,pic1')->where($where)->order('ymd desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
			$Page->setConfig('theme', '%UP_PAGE% %DOWN_PAGE%'); //设置显示的样式
			$Page->setConfig('next', '下一篇'); //设置显示的样式
			$Page->setConfig('prev', '上一篇');
			$show = $Page->show();
			$this->assign('page', $show);
			$this->assign('arts', $arts);
			$found = M('foud')->find(1);
			$found['time'] = time();
			$this->assign('found', $found);
			if ($cid == 1) {
				$this->display('./xin/xinGrow.html');
			}
			if ($cid == 2) {
				$this->display('./xin/xinSchool.html');
			}
			if ($cid == 3) {
				$this->display('./xin/xinRead.html');
			}
			if ($cid == 4) {
				$this->display('./media/story.html');
			}
			if ($cid == 5) {
				$this->display('./media/video.html');
			}
			if ($cid == 6) {
				$this->display('./media/report.html');
			}
		} else {
			$this->ajaxReturn(ajax_data(0, '参数错误'));
		}
	}

	/**
	 * 详情页
	 */
	public function art() {
		$aid = I('aid/d');
		$new = I('new/d');
		if ($aid) {
			$where['is_del'] = 0;
			$art = D('article')->where($where)->find($aid);
			if ($new == 1) {
//                全部节点新闻
				$where['cid'] = 7;
				$list = D('article')->where($where)->field('aid,title,ymd')->order('ymd desc')->select();
				foreach ($list as $k => $v) {
					if ($v['aid'] == $aid) {
						unset($list[$k]);
						array_unshift($list, $v);
					}
				}
				// print_r($list);die;
				$this->assign('art', $art);
				$this->assign('list', $list);
				$this->display('./news/news1.html');
			} else {
				//详情页
				$this->assign('art', $art);
				if ($art['cid'] == 5) {
					$this->display('./media/threeVideo.html');
				} else {
					$this->display('./media/threeNews.html');
				}
			}
		}
	}

	public function system() {
		$system = D('system')->find(1);
		$this->ajaxReturn(ajax_data(1, '', $system));
	}

	public function search() {
		$where['title'] = array("like", "%" . trim(I('get.search/string')) . "%");
		if (!empty(I('get.search/string'))) {
			$article = D('article')->where($where)->field('aid,title,content,pic1,ymd')->order('ymd desc')->select();
			$this->assign('articles', $article);
		}
		$this->assign('key_search', I('get.search/string'));
		$this->display('./aboutXR/search.html');
	}
}